﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestBat.Models.Extensions
{
    public class EnumerableExtensions
    {
        public static IEnumerable<T> Subtract<T>(IEnumerable<T> source, IEnumerable<T> other, IEqualityComparer<T> comp)
        {
            Dictionary<T, object> dict = new Dictionary<T, object>(comp);
            foreach (T item in source)
            {
                dict[item] = null;
            }

            foreach (T item in other)
            {
                dict.Remove(item);
            }

            return dict.Keys;
        }

        public static IEnumerable<T> Subtract<T>(IEnumerable<T> source, IEnumerable<T> other)
        {
            Dictionary<T, object> dict = new Dictionary<T, object>(EqualityComparer<T>.Default);
            foreach (T item in source)
            {
                dict[item] = null;
            }

            foreach (T item in other)
            {
                dict.Remove(item);
            }

            return dict.Keys;
        }
    }
}
